package com.example.okhttp0306;

import org.junit.Test;

import java.io.File;
import java.io.IOException;

import okhttp3.Call;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;

public class FileGoIntent {
    @Test
    public void FileGoIntent() throws IOException {
        OkHttpClient okHttpClient = new OkHttpClient();
        File file1 = new File("C:\\Users\\十亿少女的梦\\Desktop\\1.txt");
        File file2 = new File("C:\\Users\\十亿少女的梦\\Desktop\\2.txt");
        MultipartBody build = new MultipartBody.Builder()
                .addFormDataPart("file1", file1.getName(), RequestBody.create(file1, MediaType.parse("text/plain")))
                .addFormDataPart("file2", file2.getName(), RequestBody.create(file2, MediaType.parse("text/plain")))
                .build();
        Request request = new Request.Builder().url("https://www.httpbin.org/get?a=1&b=2").post(build).build();
        Call call = okHttpClient.newCall(request);
        Response response = call.execute();
        System.out.println(response.body().string());
    }
}
